package com.pg.service.impl;

import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pg.entity.rz.EipDataSynchronizationInfo;
import com.pg.mapper.EipDataSynchronizationInfoMapper;
import com.pg.service.EipDataSynchronizationInfoService;

/**
 * <p>
 * 日志同步 服务实现类
 * </p>
 *
 * @Author likl
 * @since 2018-12-28
 */
@Service
@DS("proxyDs")
@Primary
public class EipDataSynchronizationInfoServiceImpl extends ServiceImpl<EipDataSynchronizationInfoMapper, EipDataSynchronizationInfo> implements EipDataSynchronizationInfoService {

    @Autowired
    private EipDataSynchronizationInfoMapper eipDataSynchronizationInfoMapper;

    @Override
    public String selectSuccessNum(EipDataSynchronizationInfo eipDataSynchronizationInfo) {
        return eipDataSynchronizationInfoMapper.selectSuccessNum(eipDataSynchronizationInfo);
    }

    @Override
    public IPage<EipDataSynchronizationInfo> selectForList(Page<EipDataSynchronizationInfo> page, EipDataSynchronizationInfo eipDataSynchronizationInfo, Date synchronizationDateStartBegin, Date synchronizationDateStartFinish) {
        LambdaQueryWrapper<EipDataSynchronizationInfo> queryWrapper = new LambdaQueryWrapper<>();
        //数据来源
        if (StringUtils.isNotEmpty(eipDataSynchronizationInfo.getDataSource())) {
            queryWrapper.like(EipDataSynchronizationInfo::getDataSource, eipDataSynchronizationInfo.getDataSource());
        }
        //供应商名称
        if (StringUtils.isNotEmpty(eipDataSynchronizationInfo.getSupplierCode())) {
            queryWrapper.like(EipDataSynchronizationInfo::getSupplierCode, eipDataSynchronizationInfo.getSupplierCode());
        }
        //种类编码
        if (StringUtils.isNotEmpty(eipDataSynchronizationInfo.getSubclassCode())) {
            queryWrapper.like(EipDataSynchronizationInfo::getSubclassCode, eipDataSynchronizationInfo.getSubclassCode());
        }
        //起始时间(起)
        if (synchronizationDateStartBegin != null) {
            queryWrapper.ge(EipDataSynchronizationInfo::getSynchronizationDateStart, synchronizationDateStartBegin);
        }
        //起始时间(止)
        if (synchronizationDateStartFinish != null) {
            queryWrapper.le(EipDataSynchronizationInfo::getSynchronizationDateStart, synchronizationDateStartFinish);
        }
        queryWrapper.orderByDesc(EipDataSynchronizationInfo::getSynchronizationDateStart);
        return eipDataSynchronizationInfoMapper.selectPage(page, queryWrapper);
    }
}
